package elicecn.util;

import java.util.Calendar;
import java.util.Date;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

/**
 * 日期工具
 * 
 * @author 屹砾
 * @email eli.wuhan@gmail.com
 * @time 2009-9-8
 */
public class DateUtils {
	private static Log log = LogFactory.getLog(DateUtils.class);

	public static long calcDayFromBirth(int year, int month, int day) {
		Date from = getDate(year, month, day);
		Date to = new Date();
		return calcDayBetweenDates(from, to);
	}

	public static Date getDate(int year, int month, int day) {
		Calendar cale = Calendar.getInstance();
		cale.set(Calendar.YEAR, year);
		cale.set(Calendar.MONTH, month - 1);
		cale.set(Calendar.DAY_OF_MONTH, day);
		return cale.getTime();
	}

	public static long calcDayBetweenDates(Date from, Date to) {
		return (to.getTime() - from.getTime()) / (3600000 * 24);
	}

	public static void main(String[] args) {
		log.info(calcDayBetweenDates(getDate(1958, 5, 20), new Date()));
		log.info(calcDayBetweenDates(getDate(1984, 3, 19), new Date()));
		log.info(calcDayBetweenDates(getDate(1988, 11, 30), new Date()));
		log.info(calcDayBetweenDates(getDate(1984, 3, 19),
				getDate(1988, 11, 30)));
		log.info(1717 / 365d);
	}
}
